﻿using Csharp接口练习题2;
using System;

namespace Csharp接口练习题2
{

    //多态来模拟移动硬盘、u盘、MP3插到电脑上读取数据

    public interface IUSB 
    {
        void Connect();
        void ReadDate();
    }


    class HardDisk :IUSB
    {
        public string name;
        public bool isConnected;//判断是否连接上

        //构造函数
        public HardDisk() 
        {
            name = "移动硬盘";
        }



        public void Connect()
        {
            Console.WriteLine("连接上了");
            isConnected = true;
        }

        public void ReadDate()
        {
            if (isConnected)
            {
                Console.WriteLine("{0}读取到了", name);
            }
            else 
            {
                Console.WriteLine("读取失败请链接电脑");
            }
           
        }
    }

    class UDisk : IUSB

    {
        public string name;
        public bool isConnected;//判断是否连接上
        public UDisk()
        {
            name = "u盘";
        }

        public void Connect()
        {
            Console.WriteLine("{0}连接上了",name);
        }

        public void ReadDate()
        {
            if (isConnected)
            {
                Console.WriteLine("{0}读取到了", name);
            }
            else
            {
                Console.WriteLine("读取失败请链接电脑");
            }
        }
    }


    class MP3:IUSB
    {
        public string name;
        bool isConnected;//判断是否连接上
        public MP3() 
        {
            name = "MP3";
            isConnected = false;
        }

        public void Connect()
        {
            Console.WriteLine("{0}连接上了",name);
        }

        public void ReadDate()
        {
            if (isConnected)
            {
                Console.WriteLine("{0}读取到了", name);
            }
            else
            {
                Console.WriteLine("读取失败请链接电脑");
            }
        }
    }



    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}
